package 链表;

public class _206_反转链表 {

    public static class ListNode {
        int val;
        ListNode next;
        ListNode() {}

        ListNode(int val) {
            this.val = val;
        }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

  //反转链表
    public ListNode reverseList(ListNode head) {
        if(head==null){
            return head;
        }
        ListNode pre=null;
        ListNode nextNode=null;
        while(head!=null){
            nextNode=head.next;
            head.next=pre;
            pre=head;
            head=nextNode;
        }
        return pre;
    }
}
